/*
 * @Descripttion: 护士获取患者的药品订单
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-05 20:32:39
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-05 22:31:04
 */


const DB = require('../../lib/DB')
const { Fail, Success } = require('../../lib/Response')
module.exports = async function (ctx, next) {
    try {
        const buy_medicine = (await DB.models.buy_medicine.findAll({
            include: [
                {
                    model: DB.models.user,
                    as: 'nurse'
                },
                {
                    model: DB.models.patient,
                    as: 'patient'
                },
                {
                    model: DB.models.medicine_lib,
                    as: 'medicine_lib'
                },
            ]
        })).map(e => e.toJSON())
        ctx.body = new Success(buy_medicine)
        await next()
    } catch (e) {
        ctx.body = new Fail(e.message)
    }
}